<?php
class MineVo extends SzAbstractMySqlVo
{

    private $userId;
    private $drop;
    private $requireId;
    private $exp;

    /**
     * Initialize MineVo.
     *
     * @param $userId
     * @param $drop
     * @param $requireId
     * @param $exp
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return MineVo
     */
    public function __construct($userId, $drop, $requireId, $exp, $isInsert = false) {
        $this->userId = $userId;
        $this->drop = json_decode($drop, true);
        $this->requireId = $requireId;
        $this->exp = $exp;

        $this->isInsert = $isInsert;
        $this->voClassName = 'MineVo';
        $this->ormName = 'Mine';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'drop' => ($needEncode) ? $this->getDrop() : $this->getRawDrop(),
            'requireId' => $this->getRequireId(),
            'exp' => $this->getExp(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'drop' => ($needEncode) ? $this->getDrop() : $this->getRawDrop(),
            'requireId' => $this->getRequireId(),
            'exp' => $this->getExp(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getUserId(),
            $this->getDrop(),
            $this->getRequireId(),
            $this->getExp(),
        );
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($val)
    {
        $this->saveColumnStatus(0, $this->userId);
        $this->userId = $val;
    }

    public function getDrop()
    {
        return json_encode($this->drop);
    }

    public function getRawDrop()
    {
        return $this->drop;
    }

    public function setDrop($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 512) {
            SzLogger::get()->error('[MineVo] The length of column drop exceed the limit, length / limit: ' . $encodedLength . ' / 512');
            throw new SzException(10522, array('MineVo', '512', $encodedLength));
        } else if ($encodedLength > 460) {
            SzLogger::get()->warn('[MineVo] The length of column drop exceed the warning level, length / limit: ' . $encodedLength . ' / 512');
        }
        $this->saveColumnStatus(1, $this->drop);
        $this->drop = $val;
    }

    public function getRequireId()
    {
        return $this->requireId;
    }

    public function setRequireId($val)
    {
        $this->saveColumnStatus(2, $this->requireId);
        $this->requireId = $val;
    }

    public function getExp()
    {
        return $this->exp;
    }

    public function setExp($val)
    {
        $this->saveColumnStatus(3, $this->exp);
        $this->exp = $val;
    }

}